{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.随机数生成六个班的考试成绩，3门考试：Python、数学、语文。每个班50人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr=np.random.randint(0,100,size=(6,50,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.将六个班的考试成绩进行合并得到score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "score=np.reshape(arr,(-1,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(300, 3)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.生成性别数组sex，水平叠加数组sex和score得到data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#生成性别数组sex,其中1代表男生，0代表女生\n",
    "sex=np.random.randint(0,2,size=(300,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#水平叠加数组sex和score得到data\n",
    "#data=np.concatenate([sex,score],axis=1)\n",
    "data=np.hstack((sex,score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(300, 4)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.分别计算男女生各科成绩统计指标：最小值、最大值、平均分、中位数、标准差m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#男生的3门考试：Python、数学、语文\n",
    "maleScore=data[data[:,0]==0][:,1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#女生的3门考试：Python、数学、语文\n",
    "femaleScore=data[data[:,0]==1][:,1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "男生各科成绩最小值： [0 0 0]\n",
      "男生各科成绩最大值： [98 99 99]\n",
      "男生各科成绩平均分： [53.66060606 50.84242424 46.47878788]\n",
      "男生各科成绩中位数： [56. 53. 44.]\n",
      "男生各科成绩标准差： [27.22042392 28.7716088  27.84885349]\n"
     ]
    }
   ],
   "source": [
    "print(\"男生各科成绩最小值：\",maleScore.min(axis=0))\n",
    "print(\"男生各科成绩最大值：\",maleScore.max(axis=0))\n",
    "print(\"男生各科成绩平均分：\",maleScore.mean(axis=0))\n",
    "print(\"男生各科成绩中位数：\",np.median(maleScore,axis=0))\n",
    "print(\"男生各科成绩标准差：\",np.std(maleScore,axis=0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "女生各科成绩最小值： [0 0 0]\n",
      "女生各科成绩最大值： [99 98 99]\n",
      "女生各科成绩平均分： [49.04444444 49.96296296 48.38518519]\n",
      "女生各科成绩中位数： [50. 51. 47.]\n",
      "女生各科成绩标准差： [30.16838342 27.92487472 28.47376575]\n"
     ]
    }
   ],
   "source": [
    "print(\"女生各科成绩最小值：\",femaleScore.min(axis=0))\n",
    "print(\"女生各科成绩最大值：\",femaleScore.max(axis=0))\n",
    "print(\"女生各科成绩平均分：\",femaleScore.mean(axis=0))\n",
    "print(\"女生各科成绩中位数：\",np.median(femaleScore,axis=0))\n",
    "print(\"女生各科成绩标准差：\",np.std(femaleScore,axis=0))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
